package com.hyg.module_report.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hyg.lib_base.mainUtils.StatusBarUtil;
import com.hyg.lib_base.mainUtils.Utils;
import com.hyg.lib_common.Base.BaseActivity;
import com.hyg.module_report.R;
import com.hyg.module_report.model.V2AdviceDetailData;

/**
 * 养生建议点击后查看详情内容的页面
 */
public class HealthAdviceDetailActivity extends BaseActivity {

    private ImageView back;
    private ImageView detail_image;
    private TextView detail_title;
    private TextView Subtitle1, ShortEssay1, Subtitle2, ShortEssay2, Subtitle3, ShortEssay3, Subtitle4, ShortEssay4, Subtitle5, ShortEssay5;
    //    private TextView line1,line2,line3,line4;
    private V2AdviceDetailData AdviceData;
    private LinearLayout baseLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
//        setDark(true);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_health_advice_detail);
        StatusBarUtil.setStatusBar(1, this, getResources().getColor(R.color.white), 00, null, null, true);
        init();
    }

    public void init() {
        back = (ImageView) findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (Utils.isFastClick()) {
                    return;
                }
                finish();
                overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
            }
        });
        detail_title = (TextView) findViewById(R.id.detail_title);
        detail_image = (ImageView) findViewById(R.id.detail_image);
        baseLayout = (LinearLayout) findViewById(R.id.ll_base);
        setData();
    }

    public void setData() {
        Intent it = getIntent();
        if (null != it.getParcelableExtra("AdviceData")) {
            AdviceData = (V2AdviceDetailData) it.getParcelableExtra("AdviceData");
            detail_title.setText(AdviceData.getYsName());
            Glide.with(this).load(AdviceData.getImageUrl()).into(detail_image);

            if (!TextUtils.isEmpty(AdviceData.getRawMaterial())) {
                addView("原料:", cutContent(AdviceData.getRawMaterial()));
            }
            if (!TextUtils.isEmpty(AdviceData.getPosition())) {
                addView("定位:", cutContent(AdviceData.getPosition()));
            }
            if (!TextUtils.isEmpty(AdviceData.getPractice())) {
                addView("做法:", cutContent(AdviceData.getPractice()));
            }
            if (!TextUtils.isEmpty(AdviceData.getOperationUsage())) {
                addView("操作:", cutContent(AdviceData.getOperationUsage()));
            }
            if (!TextUtils.isEmpty(AdviceData.getPrinciple())) {
                addView("作法:", cutContent(AdviceData.getPrinciple()));
            }
            if (!TextUtils.isEmpty(AdviceData.getEffect())) {
                addView("功效:", cutContent(AdviceData.getEffect()));
            }
            if (!TextUtils.isEmpty(AdviceData.getBeCareful())) {
                addView("注意:", cutContent(AdviceData.getBeCareful()));
            }
            if (!TextUtils.isEmpty(AdviceData.getTaboo())) {
                addView("禁忌:", cutContent(AdviceData.getTaboo()));
            }

        }
    }

    // 截取两个指定字符串之间的内容
    public String getInsideString(String str, String strStart, String strEnd) {
        if (str.indexOf(strStart) < 0) {
            return "";
        }
        if (str.indexOf(strEnd) < 0) {
            return "";
        }
        return str.substring(str.indexOf(strStart) + strStart.length() - 1, str.indexOf(strEnd) + 1);
    }


    /**
     * description: 修改1.0数据以【】开头的逻辑
     * @author visitant
     * @time 2021/1/8 10:55
     */
    public String cutContent(String data){
        if(data.startsWith("【")){
            return data.substring(data.indexOf("】")+1);
        }else{
            return data;
        }
    }

    /**
     * description: 添加文字显示项
     * @param  title 显示标题
     * @param  content 显示内容
     * @author visitant
     * @time 2021/1/8 10:56
     */
    public void addView(String title, String content) {
        View view = LayoutInflater.from(this).inflate(R.layout.item_advice_text, null);
        TextView tv_title = view.findViewById(R.id.tv_title);
        TextView tv_content = view.findViewById(R.id.tv_content);
        tv_title.setText(title);
        tv_content.setText("\u3000\u3000" + content);
        baseLayout.addView(view);
    }

}